from django.db import models

# Create your models here.

# environment_type = (
# 	(0,'本地服务环境'),(1, '开发环境'), (2, '测试环境'), (3, '预发布环境'), (4, '正式环境')
# )
# project_type = (
# 	(0,'官网'),(1, '企训'), (2, '春华'), (3, 'Java Im服务'),(4,'官网ubas'),(5,'企训ubas')
# )


class ProjectName(models.Model):
	id = models.AutoField(primary_key=True)
	projectname = models.CharField(max_length=16,verbose_name="所属项目",unique=True)
	def __str__(self):
		return self.projectname
	class Meta:
		db_table = 'OPS_projectname'
		verbose_name_plural = '项目名称'

class PathConfig(models.Model):
	id = models.AutoField(primary_key=True)
	pathname = models.CharField(max_length=16,verbose_name="所属环境",unique=True)
	def __str__(self):
		return self.pathname
	class Meta:
		db_table = 'OPS_PathConfig'
		verbose_name_plural = '运行环境名称'


class PlatformLink(models.Model):
	'''用于管理者添加公司的平台urls的相关信息，类似wiki的记录页面'''
	id = models.AutoField(primary_key=True)
	name = models.CharField(max_length=10,null=False,verbose_name='应用名称')
	link = models.CharField(max_length=200,null=False,verbose_name='Url链接')
	# environment = models.IntegerField(choices=environment_type,verbose_name='运行环境')
	# #(0,'本地服务环境'),(1, '开发环境'), (2, '测试环境'), (3, '预发布环境'), (4, '正式环境')
	environment = models.ForeignKey('PathConfig',verbose_name="所属环境")
	application = models.CharField(max_length=100,null=False,verbose_name='用途')
	remarks =  models.TextField(max_length=250,null=True,verbose_name='备注')
	def __str__(self):
		return self.name
	class Meta:
		db_table = 'OPS_PlatformLink'
		verbose_name_plural = '应用信息记录'

class RedisConfig(models.Model):
	'''Redis配置'''
	id = models.AutoField(primary_key=True)
	# project =  models.IntegerField(choices=project_type, verbose_name='项目')
	project = models.ForeignKey('ProjectName',verbose_name="所属项目")
	redisname = models.CharField(max_length=16,verbose_name="别名",unique=True)
	hostname = models.CharField(max_length=10,verbose_name='主机名')  #等做了cmdb则需要换成选择主机
	hostip = models.GenericIPAddressField(unpack_ipv4=False,verbose_name='主机IP')
	port = models.CharField(max_length=8,verbose_name='端口')
	auth = models.CharField(max_length=64,verbose_name='认证密码')
	dbcount = models.IntegerField(verbose_name='数据库数量',default=16)
	environment = models.ForeignKey('PathConfig', verbose_name="所属环境")
	# environment = models.IntegerField(choices=environment_type, verbose_name='运行环境')
	#(0,'本地服务环境'),(1, '开发环境'), (2, '测试环境'), (3, '预发布环境'), (4, '正式环境')
	remarks =  models.TextField(max_length=250,null=True,verbose_name='备注')
	def __str__(self):
		return self.hostname
	class Meta:
		db_table = 'OPS_RedisConfig'
		verbose_name_plural = 'Redis配置'



